var util = require('../../utils/util');
var wxApi = require('../../utils/wxApi');
var wxRequest = require('../../utils/wxRequest');
import config from '../../utils/config';

var app = getApp();
var that;

Page({
  data: {
   back:0
   ,isload:0
  },
  handleMsg: function (e) {
    if(that.data.isload == 1){
        return false;
    }
    that.data.isload = 1;

    var data = e.detail.data[0];

    if(util.judge.isString(data) ){
       data = util.toobj(data);
    }
  
    // var user =  app.globalData.user;
    // if(data.unionid != app.globalData.user.unionId){
    //   util.alert("unionid 不一致,请联系客服");
    //   return false;
    // }

    var params = {
        city:data.city,
        phone:data.phone,
        openid2:data.openid,
        unionid:data.unionid
    };

    that.data.prevPage.zunew(params);
    
 },
  onLoad: function (options) {
    that = this;
    that.data.isload = 0;
    var pages = getCurrentPages();
    that.data.prevPage = pages[pages.length - 2];
    var user = null;
    that.setData({
      user:that.data.prevPage.data.user
    });

    if( !util.judge.isNull(options.back) ){
        that.data.back = parseInt(options.back);
    }

    wx.setNavigationBarTitle( { title: "同步/注册账号" });

    app.getUserInfo()
    .then(res => {
      if(util.judge.isObject(res)){
        var dd = wx.getStorageSync('data');
        if(!util.judge.isNull(dd) && dd.user.isgl == 1){
          
            that.data.prevPage.setData({
                isgl:1
            });

            wx.navigateBack({
                delta: 1
            })
        }
      }
    })
    .catch(res => {
        util.alert_catch(res);
    })
    .finally(function (res) {
        util.hideLoading();
    });


   

  },
  onReady: function () {
  },

})